﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using XCode.Membership;

namespace WpfBill.GUI
{
    /// <summary>
    /// WinChangePwd.xaml 的交互逻辑
    /// </summary>
    public partial class WinChangePwd : Window
    {
        public WinChangePwd()
        {
            InitializeComponent();
        }

        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string oldPwd = txtPwd.Password;
                string pwd = txtNPwd.Password;
                var user = UserX.Login("admin", oldPwd);
                if (user == null)
                {
                    MessageBox.Show("修改失败，旧密码错误");
                    return;
                }
                user.Password = pwd;
                user.Save();
                DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("修改失败，" + ex.Message);
            }
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            this.Close();
        }
    }
}
